home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / mus2v131.zip / WrtSgLst.cmd < prev   
OS/2 REXX Batch file  |  1996-02-08  |  3KB  |  120 lines

  1. /* ########################################################################
  2.  
  3.    This REXX script will communicate with a running Module Player that
  4.    support a Command Pipe.
  5.  
  6.    The Following commands are used
  7.       Query Song  -- Returns three lines, first is the file name, second is the
  8.                      index and third is the song title. They represent
  9.                      the currently playing song.
  10.       SongList EraseIndx -- Nukes 1 item in the list (by index)
  11.       Play Next -- Plays the next song
  12.  
  13.    ########################################################################
  14. */
  15. '@echo off'                       /* Don't echo commands */
  16. say " Module Player Songlist Generator V1.0                                    Ethos"
  17.    call OpenPlayer
  18.    if Result <> 0 then do
  19.       say "Error" Error
  20.       return
  21.    end
  22.  
  23.    if (arg(1) = '') then do
  24.       say "Require a filename to write the songlist to."
  25.       return
  26.    end
  27.  
  28.    if CallPlayer("Query","SongList","") <> 0 then do
  29.       say "Error" Error
  30.       return
  31.    end
  32.  
  33.    'del' arg(1)
  34.    I = 2;
  35.    do while (I <= Result.0)
  36.       call lineout arg(1),Result.I
  37.       I = I + 1
  38.    end
  39.  
  40. return
  41.  
  42. /* ########################################################################
  43.  
  44.    Function - CallPlayer
  45.    Eg - if (CallPlayer("Query","Song","") <> 0) then Error
  46.  
  47.    Description - This procedure sends a command message to the player.
  48.                  An error is returned if the player doesn't understand
  49.                  the message or something else is wrong.
  50.                    Result - A stem containing each line of the result
  51.                    Error - Global error code
  52.  
  53.    ########################################################################
  54. */
  55. CallPlayer: procedure expose Result. Player Error
  56.    parse arg Command, SCommand, Arg
  57.  
  58.    Error = ""
  59.    Result.0 = 0
  60.  
  61.    /* Player not loaded */
  62.    if (Player = "") then do
  63.       Error = "Player not Inited"
  64.       return 1
  65.    end
  66.  
  67.    call lineout Player,Command SCommand Arg
  68.  
  69.    /* Get all the results */
  70.    do while (1)
  71.       Line = linein(Player)
  72.  
  73.       /* Error or something */
  74.       if (pos("!!",Line) = 1) then do
  75.          if (Line = "!! OK") then
  76.             return 0
  77.          Error = substr(Line,4)
  78.          return 1
  79.       end;
  80.  
  81.       Result.0 = Result.0 + 1
  82.       I = Result.0
  83.       Result.I = Line
  84.    end
  85.  
  86. return 0
  87.  
  88. /* ########################################################################
  89.  
  90.    Function - OpenPlayer
  91.    Eg - call OpenPlayer
  92.  
  93.    Description - This procedure opens the pipe and sets the following:
  94.                    Player - The name of the pipe - \pipe\Player
  95.                    Version - The pipe comminication version
  96.                    Type - The program running on the other end, 'Text UI'
  97.                    Error - Global Error Code
  98.  
  99.    ########################################################################
  100. */
  101. OpenPlayer:procedure expose Player Version Type Error
  102.    Error = ""
  103.  
  104.    Result = Stream("\pipe\ModulePlayer","C","OPEN");
  105.    if (Result <> "READY:") then do
  106.       Error = "Unable to communicate with the  Player, is it running?"
  107.       Player = ""
  108.       return 1
  109.    end
  110.    Player = "\pipe\ModulePlayer"
  111.  
  112.    /* Get the version */
  113.    S = linein(Player)
  114.    parse var S 'V' Version .
  115.    Type = linein(Player)
  116. return 0
  117.  
  118.  
  119.  
  120.